package com.hq.fxh.No1_Infromation.Video.Adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.hq.fxh.Modle.GetEntertainmentListResInfo;
import com.hq.fxh.R;
import com.hq.fxh.Utils.Tool;

import java.util.List;

import jp.wasabeef.glide.transformations.BlurTransformation;

/**
 * /**
 *
 * @author 薛
 * @ClassName
 * @Description :视频页面适配器
 * @Created 2017/8/9
 * @Email xlwenhao1858@sina.com
 */


public class Adapter_videolist extends BaseAdapter {
    List<GetEntertainmentListResInfo> data;

    public void setData(List<GetEntertainmentListResInfo> data) {
        this.data = data;
    }

    @Override
    public int getCount() {
        return data == null ? 0 : data.size();
    }

    @Override
    public GetEntertainmentListResInfo getItem(int i) {
        return data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;
        ViewHolder viewHolder = null;
        if (view == null || !(view.getTag() instanceof ViewHolder)) {
            view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_videolist, null);
            viewHolder = new ViewHolder(view);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        GetEntertainmentListResInfo getEntertainmentListResInfo = data.get(position);

        String subject_img_url = getEntertainmentListResInfo.getSubject_img_url();
        Tool.setStringToText(viewHolder.videoFragmentVideoName, getEntertainmentListResInfo.getSubject_title());
        Tool.setStringToText(viewHolder.videoFragmentTime,getEntertainmentListResInfo.getSubject_item_count());
        Tool.setStringToText(viewHolder.videoFragmentNum, getEntertainmentListResInfo.getAction_num() + "");
        Tool.setUrlToImage1(parent.getContext(), subject_img_url, viewHolder.videoListImage);
        Glide.with(parent.getContext()).load(subject_img_url ).bitmapTransform(new BlurTransformation(parent.getContext(), 22)).into(viewHolder.videoListImageBg);
        return view;
    }

    static class ViewHolder {
        protected ImageView videoListImage;
        protected ImageView videoListImageBg;

        protected TextView videoFragmentVideoName;
        protected TextView videoFragmentNum;
        protected TextView videoFragmentTime;

        ViewHolder(View rootView) {
            initView(rootView);
        }

        private void initView(View rootView) {
            videoListImage = (ImageView) rootView.findViewById(R.id.videoList_Image);
            videoListImageBg = (ImageView) rootView.findViewById(R.id.videoList_Image_bg);

            videoFragmentVideoName = (TextView) rootView.findViewById(R.id.videoFragment_videoName);
            videoFragmentNum = (TextView) rootView.findViewById(R.id.videoFragment_Num);
            videoFragmentTime = (TextView) rootView.findViewById(R.id.videoFragment_Time);
        }
    }
}
